package design.simdi.code.final_paper.site.panels;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import design.simdi.code.final_paper.core.entities.Person;
import design.simdi.code.final_paper.core.entities.User;
import design.simdi.code.final_paper.core.services.ApplicationService;
import design.simdi.code.final_paper.core.services.UserService;
import design.simdi.code.final_paper.site.application.MyAuthenticatedWebSession;

/**
 * 
 * @author Marius Dumitriu - (Jun 5, 2010 - 9:01:28 PM)
 * 
 */
public abstract class PagePanel extends Panel {

	private static final long serialVersionUID = 1L;
	@SpringBean
	private UserService userService;
	@SpringBean
	private ApplicationService applicationService;

	public PagePanel(String id) {
		super(id);
		panelInit();
	}

	public PagePanel(String id, IModel<?> model) {
		super(id, model);
		panelInit();
	}

	public abstract void panelInit();

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public UserService getUserService() {
		return userService;
	}

	public Person getCurrentPerson() {
		User currentUser = ((MyAuthenticatedWebSession) getSession()).getCurrentUser();

		Person p = userService.findPersonByUser(currentUser);
		return p;
	}

	public int getRowsPerPage() {
		return 10;
	}

	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
	}

	public ApplicationService getApplicationService() {
		return applicationService;
	}

}
